/*********************************************************************************
 * SIMPLE LISTS, A SIMPLE C LIBRARY FOR LINKED LISTS.
 * Copyright (C) 2012 Fabian Ström
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2.0, as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *********************************************************************************/

#include <stdlib.h>

/***************
* LIST STRUCT *
***************/

struct list_cell {
	union {
		int i;
		char c;
		char *cptr;
		float f;
		struct list_cell *cell;
	} val;
	struct list_cell *next;
};

/*************************
 * ACCESSING FUNCTIONS   *
 * used to get a certain *
 * cell.                 *
 *************************/

/* get the next cell in lst 
 * 
 * Returns the next cell 
 * or null if next cell does not exist 
 */
struct list_cell *list_getNext(struct list_cell *cell);

/* get last cell in list 
 *
 * Returns the last cell in list lst
 */
struct list_cell *list_getLast(struct list_cell *lst);

/* get n:th cell in lst, 
 *
 * Returns n:th cell, null if (max < 1 or length < max)
 */
struct list_cell *list_getNth(struct list_cell *lst, int n);
struct list_cell *list_getNthHelper(struct list_cell *lst, int max, int pos);

/**************************
 * MANIPULATION FUNCTIONS *
 * used to manipulate the *
 * chain of cells.        *
 **************************/

/* join cell to lst */
void list_join(struct list_cell *lst, struct list_cell *cell); 

/* remove the cell after cell */
void list_removeCellAfter(struct list_cell *cell);

/* delete a list */
void list_deleteList(struct list_cell *cell);

/* get length of a list */
int list_listLength(struct list_cell *list);
int list_listLengthHelper(struct list_cell *list, int pos);

/* apply func to each cell in lst 
 *
 * prototype for func:
 * void func (*cell) { ... }
 * */
void list_map(struct list_cell *lst, void (*func)(struct list_cell *cell));

/***************************
 * LIST CREATION FUNCTIONS *
 * used to create and      *
 * initialize lists.       *
 ***************************/

/* create a list of size n
 *
 * Return the list.
 */
struct list_cell *list_createListOfSize(int size);

/* create a new cell 
 *
 * Returns a list_cell or NULL if size < 1.
 */
struct list_cell *list_newCell();
